import request from "@/utils/request";
import { AxiosPromise } from "axios";
import {
  ModelAdd,
  ModelStatus,
  ModelResult,
  ModelSort,
  ModelResultList,
} from "./types";

// 轮播图管理 - 查询列表
export function getBannerList(data: string): AxiosPromise<ModelResultList> {
  return request({
    url: `/api/BannerImages/list?keyword=${data}`,
    method: "get",
  });
}

// 轮播图管理 - 轮播图排序
export function sortBanner(data: ModelSort): AxiosPromise<ModelResult> {
  return request({
    url: "/api/BannerImages/sorting",
    method: "patch",
    data,
  });
}

// 轮播图管理 - 轮播图状态
export function statusBanner(data: ModelStatus) {
  return request({
    url: `/api/BannerImages/status/${data.id}?enabled=${data.enabled}`,
    method: "patch",
  });
}

// 轮播图管理 - 新增轮播
export function addBanner(data: ModelAdd) {
  return request({
    url: `/api/BannerImages`,
    method: "post",
    data,
  });
}

// 轮播图管理 - 修改轮播
export function updateBanner(data: ModelAdd) {
  return request({
    url: `/api/BannerImages/${data?.id}`,
    method: "put",
    data,
  });
}

// 轮播图管理 - 删除轮播
export function deleteBanner(data: number) {
  return request({
    url: `/api/BannerImages/${data}`,
    method: "delete",
  });
}

// 轮播图管理 - 轮播图上传
export function uploadBanner(): AxiosPromise<ModelResult> {
  return request({
    url: `/api/BannerImages/upload`,
    method: "post",
  });
}
